package com.serialcommunication.gui.component;

import java.awt.GridBagLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.text.MaskFormatter;

import com.serialcommunication.constants.ProtocolConstants;
import com.serialcommunication.enums.Engine;
import com.serialcommunication.gui.frame.MainFrame;
import com.serialcommunication.interfaces.IAction;

public class BaseComponent {
	
	/**
	 * which action this component represents
	 */
	private IAction action;
	
	/**
	 * Which engine this component is assigned
	 */
	private Engine engine;

	/**
	 * Used as identifier. Has to be the same as the Action name. Then the
	 * components can be found when action is received
	 */
	private String name;

	/**
	 * Value to display in GUI
	 */
	private String title; 
	
	private MainFrame frame;
	
	/** 
	 * Panel providing the GUI elements
	 */
	private JPanel panel;
	

	public BaseComponent(Engine pEngine, IAction pAction, MainFrame pFrame) {
		name = pAction.getName();
		frame = pFrame;
		engine = pEngine;
		title = pAction.getTitle();
		action = pAction;
		panel = new JPanel(new GridBagLayout());
	}
	
	public void setPositionOfPanel(int x, int y, int width, int height) {
		panel.setBounds(x, y, width, height);
	}

	public Engine getEngine() {
		return engine;
	}

	public void setEngine(Engine engine) {
		this.engine = engine;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public JPanel getPanel() {
		return panel;
	}

	public void setPanel(JPanel panel) {
		this.panel = panel;
	}

	public IAction getAction() {
		return action;
	}
	
	public boolean isBinary() {
		boolean retValue = ((getAction().getCommand().equals(ProtocolConstants.BINARY_COMMAND)) ? true : false);
		return retValue;
	}

	public MainFrame getFrame() {
		return frame;
	}
}
